﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DateGeneratorTests
{
    public static class AssertThrows
    {
        public static T Throws<T>(Action a) where T : Exception
        {
            try
            {
                a.Invoke();
            }
            catch (T expectedexception)
            {
                if (typeof(T) != expectedexception.GetType())
                    throw new AssertFailedException(string.Format("The expected exception was not thrown. A different exception: {0} was thrown", expectedexception.Message), expectedexception);
                return expectedexception;
            }
            catch (Exception e)
            {
                throw new AssertFailedException(string.Format("The expected exception was not thrown. A different exception: {0} was thrown", e.Message), e);
            }

            throw new AssertFailedException("The expected exception was not thrown. No exception was thrown!");
        }
    }
}
